
#!/usr/bin/python3
import sys
import io
import time
h="2"
def done(case,prin="my_print"):
    print(f"Printing test case {case} to {prin}.txt: ", end="",flush=True)
    for i in range(1,4):
        print(".",end="",flush=True)
        time.sleep(0.3)
    print("done.",flush=True)
    time.sleep(0.3)
def loading(h):
    for k in range(1,h+1):
        print("{}".format("."),end="",flush=True)
        time.sleep(0.3)
        if k % 3==0 and k !=h:
            print("\b\b\b", end="",flush=True)
            print("   ",end="",flush=True)
            print("\b\b\b", end="",flush=True)
    print("")

def my_print(*values,sep=' ',end='\n',file=None,flush=False):
    wp=""
    for pr in values:
        if pr != values[-1]:
            wp=wp+pr+sep
        else:
            wp=wp+pr
    wp=wp+end
    if file == None: 
        file=sys.stdout
    file.write(wp)
    if flush:
        file.flush()
with open("my_print.txt","w") as mp:
    my_print("1",h,"3",sep="[sp]",end="[ed]\n",file=mp,flush=True)
    done("1")
    my_print(f"1{h}3",end="[ed]",file=mp,flush=True)
    done("2")
    my_print("1{}3".format(h),sep="[sp]",file=mp,flush=True)
    done("3")
with open("print.txt","w") as p:
    print("1",h,"3",sep="[sp]",end="[ed]\n",file=p,flush=True)
    done("1","print")
    print(f"1{h}3",end="[ed]",file=p,flush=True)
    done("2","print")
    print("1{}3".format(h),sep="[sp]",file=p,flush=True)
    done("3","print")
with open("my_print.txt","r") as mp:
    mp_r=mp.read()
with open("print.txt","r") as p:
    p_r=p.read()
loading(9)



if mp_r == p_r:
    print("Comparing contents of my_print.txt and print.txt",end="")
    loading(6)
    print("All test cases passed.")
    
